package com.ruoyi.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.TaskPoint;
import com.ruoyi.business.service.ITaskPointService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务点位Controller
 *
 * @author Eric
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/business/point")
public class TaskPointController extends BaseController {
    @Resource
    private ITaskPointService taskPointService;

    /**
     * 查询任务点位列表
     */
    @PreAuthorize("@ss.hasPermi('business:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskPoint taskPoint) {
        startPage();
        List<TaskPoint> list = taskPointService.list(Wrappers.lambdaQuery(TaskPoint.class).
                setEntity(taskPoint));
        return getDataTable(list);
    }

    /**
     * 导出任务点位列表
     */
    @PreAuthorize("@ss.hasPermi('business:point:export')")
    @Log(title = "任务点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskPoint taskPoint) {
        List<TaskPoint> list = taskPointService.list(Wrappers.lambdaQuery(TaskPoint.class).
                setEntity(taskPoint));
        ExcelUtil<TaskPoint> util = new ExcelUtil<TaskPoint>(TaskPoint.class);
        util.exportExcel(response, list, "任务点位数据");
    }

    /**
     * 获取任务点位详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(taskPointService.getById(id));
    }

    /**
     * 新增任务点位
     */
    @PreAuthorize("@ss.hasPermi('business:point:add')")
    @Log(title = "任务点位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskPoint taskPoint) {
        return toAjax(taskPointService.save(taskPoint));
    }

    /**
     * 修改任务点位
     */
    @PreAuthorize("@ss.hasPermi('business:point:edit')")
    @Log(title = "任务点位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskPoint taskPoint) {
        return toAjax(taskPointService.updateById(taskPoint));
    }

    /**
     * 删除任务点位
     */
    @PreAuthorize("@ss.hasPermi('business:point:remove')")
    @Log(title = "任务点位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(taskPointService.removeBatchByIds(Arrays.asList(ids)));
    }

}
